$(document).ready(function(){
	if($('#test').length > 0){
		//install database
		$.ajax({
		  	url: base_url + "index.php/ajax_controller/install_database?random=" + Math.random()
		  , type: 'POST'
		  ,	success: function(result){
		  	if(result == ''){
			  	$('#test').animate({
						width:'50%'
					}, 1000, function(){
						
					});
					$('#process').html('Grunddaten installieren...');
					//install basic data
					$.ajax({
					  	url: base_url + "index.php/ajax_controller/install_basic_data?random=" + Math.random()
					  , type: 'POST'
					  ,	success: function(result){
					  	if(result == ''){
						  	$('#test').animate({
									width:'100%'
								}, 1000, function(){
									$('#process').html('Abgeschlossen');
									$('#progress_bar').addClass('progress-success');
									$('#progress_bar').removeClass('active');
									setMessage('success', 'Die Installation ist erfolgreich abgeschlossen. Bitte löschen Sie den Installations Ordner damit die Installation vollständig abgeschlossen ist.');
								});
							}else{
								//install basic data failed
								setMessage('error', 'Installation der Grunddaten ist Fehlgeschlagen!');
							}
					  }
					});
				}else{
					//install database data failed
					setMessage('error', 'Installation der Datenbank ist Fehlgeschlagen!');
				}
		  }
		});
	}
});

/**
	* sendAjaxRequest: executes an ajax request and evaluates the response
	*
	*	@param ajax_function string
	*	@param ajax_data string
	*
	*
	* @author Philipp Panka <ppanka@gedak.de>
	*/
function sendAjaxRequest(ajax_function, ajax_data){
	setMessage('warning', 'Bitte warten...');
	$.ajax({
	  	url: base_url + "index.php/ajax_controller/" + ajax_function + "?random=" + Math.random()
	  ,	data: ajax_data
	  , type: 'POST'
	  ,	dataType: 'script'
	});
}

/**
	* setMessage:  sets a Message and display it
	*
	*	@param type string
	*	@param message string
	*
	*
	* @author Philipp Panka <ppanka@gedak.de>
	*/
function setMessage(type, message){
	messagesClear();
	var messageBox = $('<div class="alert alert-'+type+' fade in"><button type="button" class="close" onclick="$(this).parent().hide(\'slow\', function(){ $(this).remove(); });">&times;</button><span class="message">'+message+'</span></div>').hide();
	$('#message-container').append(messageBox);
	messageBox.show('slow');
	
	if ($(window).scrollTop() > 0) {
		$("html, body").animate({ scrollTop: 0 }, 600);
	}	
}

/**
	* messagesClear:  clear current message
	*
	*
	* @author Philipp Panka <ppanka@gedak.de>
	*/
function messagesClear(){
	$('#message-container').empty();
}